package com.platform.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.platform.dao.MpMsgDao;
import com.platform.entity.MpMsgEntity;
import com.platform.service.MpMsgService;

/**
 * Service实现类
 *
 * @author LarkerJin
 * @email 277901879@qq.com
 * @date 2019-07-03 15:32:04
 */
@Service("mpMsgService")
public class MpMsgService {
	public static Map<Integer,MpMsgEntity> mpMsgMap = new HashMap<Integer,MpMsgEntity>();

    @Autowired
    private MpMsgDao mpMsgDao;

    public MpMsgEntity queryObject(Integer id) {
        return queryObject(id,false);
    }
    
    public MpMsgEntity queryObject(Integer id,boolean isNoCache) {
    	MpMsgEntity mpMsg = mpMsgMap.get(id);
    	if(mpMsg == null || isNoCache) {
    		mpMsg = mpMsgDao.queryObject(id);
    		mpMsgMap.put(id, mpMsg);
    	}
        return mpMsg;
    }
    
    
    public MpMsgEntity queryByAppId(String appId) {
        return mpMsgDao.queryByAppId(appId);
    }

    public List<MpMsgEntity> queryList(Map<String, Object> map) {
        return mpMsgDao.queryList(map);
    }

    public int queryTotal(Map<String, Object> map) {
        return mpMsgDao.queryTotal(map);
    }

    public int save(MpMsgEntity mpMsg) {
        return mpMsgDao.save(mpMsg);
    }

    public int update(MpMsgEntity mpMsg) {
    	mpMsgMap.remove(mpMsg.getId());
        return mpMsgDao.update(mpMsg);
    }

    public int delete(Integer id) {
    	mpMsgMap.remove(id);
        return mpMsgDao.delete(id);
    }

    public int deleteBatch(Integer[] ids) {
    	for(Integer id:ids)
        	mpMsgMap.remove(id);
        return mpMsgDao.deleteBatch(ids);
    }
}
